package edu.hcmus.sow.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllUserPreferences", query = "select myUserPreference from UserPreference myUserPreference"),
		@NamedQuery(name = "findUserPreferenceByCalendarViewMode", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.calendarViewMode = ?1"),
		@NamedQuery(name = "findUserPreferenceByCalendarViewModeContaining", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.calendarViewMode like ?1"),
		@NamedQuery(name = "findUserPreferenceByDefaultLanguage", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.defaultLanguage = ?1"),
		@NamedQuery(name = "findUserPreferenceByDefaultLanguageContaining", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.defaultLanguage like ?1"),
		@NamedQuery(name = "findUserPreferenceById", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.id = ?1"),
		@NamedQuery(name = "findUserPreferenceByPrimaryKey", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.id = ?1"),
		@NamedQuery(name = "findUserPreferenceByTheme", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.theme = ?1"),
		@NamedQuery(name = "findUserPreferenceByThemeContaining", query = "select myUserPreference from UserPreference myUserPreference where myUserPreference.theme like ?1") })
@Table(catalog = "sow", name = "user_preference")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "UserPreference")
public class UserPreference implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "DEFAULT_LANGUAGE", length = 5)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String defaultLanguage;
	/**
	 */

	@Column(name = "THEME", length = 20)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String theme;
	/**
	 */

	@Column(name = "CALENDAR_VIEW_MODE", length = 10)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String calendarViewMode;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "USER_ID", referencedColumnName = "ID", unique = true, nullable = false) })
	@XmlTransient
	User user;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setDefaultLanguage(String defaultLanguage) {
		this.defaultLanguage = defaultLanguage;
	}

	/**
	 */
	public String getDefaultLanguage() {
		return this.defaultLanguage;
	}

	/**
	 */
	public void setTheme(String theme) {
		this.theme = theme;
	}

	/**
	 */
	public String getTheme() {
		return this.theme;
	}

	/**
	 */
	public void setCalendarViewMode(String calendarViewMode) {
		this.calendarViewMode = calendarViewMode;
	}

	/**
	 */
	public String getCalendarViewMode() {
		return this.calendarViewMode;
	}

	/**
	 */
	public void setUser(User user) {
		this.user = user;
	}

	/**
	 */
	@JsonIgnore
	public User getUser() {
		return user;
	}

	/**
	 */
	public UserPreference() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(UserPreference that) {
		setId(that.getId());
		setDefaultLanguage(that.getDefaultLanguage());
		setTheme(that.getTheme());
		setCalendarViewMode(that.getCalendarViewMode());
		setUser(that.getUser());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("defaultLanguage=[").append(defaultLanguage).append("] ");
		buffer.append("theme=[").append(theme).append("] ");
		buffer.append("calendarViewMode=[").append(calendarViewMode).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof UserPreference))
			return false;
		UserPreference equalCheck = (UserPreference) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
